package com.wyp.demo.reboot;

import java.util.Map;
import java.util.Set;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

import com.wyp.demo.R;
import com.wyp.demo.utils.SysCfgDao;

public class RebootActivity extends Activity {
	Button btn1,btn2;
	private Context ct;
	private SysCfgDao sysCfgDao;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.reboot);
		btn1 = (Button)findViewById(R.id.button1);
		btn1.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				shutdownSystem();
			}
		});
		
		btn2 = (Button)findViewById(R.id.button2);
		btn2.setOnClickListener(new OnClickListener() {
			
			public void onClick(View v) {
				getControllerData();
			}
		});
	}
	private void getControllerData() {
		try {
			ct= RebootActivity.this.createPackageContext("com.cn.newcontroller", Context.CONTEXT_IGNORE_SECURITY);
			sysCfgDao = new SysCfgDao();
			sysCfgDao.openDB(ct);
			Map<String, String> params = sysCfgDao.findAll();
			Set<String> keys = params.keySet();
			for (String key : keys) {
				//System.out.println("key:"+key+"<==>value:"+params.get(key).toString());
				Log.d("Sql", "key:"+key+"<==>value:"+params.get(key).toString());
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	private void shutdownSystem() {
		try {
			Intent intent = new Intent("android.intent.action.ACTION_REQUEST_SHUTDOWN");  
			intent.putExtra("android.intent.extra.KEY_CONFIRM", false);  
			intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);  
			startActivity(intent);
		} catch (Exception e) {
			e.printStackTrace();
		} 
	}
}
